/**
  ******************************************************************************
  * @file   :   main.c
  * @version:
  * @author :
  * @brief  :
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright(c) . BLUEX Microelectronics.
  * All rights reserved.</center></h2>
  *
  *
  ******************************************************************************
  */

/* includes ------------------------------------------------------------------*/

#include "bx_kernel.h"
#include "user_app.h"
#include "bx_shell.h"
#include "bx_service_pwm.h"
#include "bx_drv_pwm.h"
#include "bx_drv_gpio.h"
#include "bx_service_gpio.h"
#include "plf.h"

/* private define ------------------------------------------------------------*/
#define    PWM0_PIN			2
#define    PWM1_PIN			3
#define    PWM2_PIN			4
#define    PWM3_PIN			5
#define	   PWM4_PIN			6
#define    BUTTON_0         15

/* private typedef -----------------------------------------------------------*/

/* private variables ---------------------------------------------------------*/

/* exported variables --------------------------------------------------------*/


/*============================= private function =============================*/

/*========================= end of private function ==========================*/


/*============================= exported function ============================*/
/** ---------------------------------------------------------------------------
 * @brief   :
 * @note    :
 * @param   :
 * @retval  :
-----------------------------------------------------------------------------*/
void user_init( void )
{
		bxs_pwm_register();
		bxs_gpio_register();
}

/** ---------------------------------------------------------------------------
 * @brief   :
 * @note    :
 * @param   :
 * @retval  :
-----------------------------------------------------------------------------*/
void user_app( void )
{
    static u8 duty_value = 0;
	u32 pin_value;
	s32 id_gpio = bxs_gpio_a_id();
	
    s32 id0 = bxs_pwm0_id();
	s32 id1 = bxs_pwm1_id();
	s32 id2 = bxs_pwm2_id();
	s32 id3 = bxs_pwm3_id();
	s32 id4 = bxs_pwm4_id();

	bx_call(id_gpio,BXM_OPEN,0,0);
	bx_set(id_gpio,BXP_MODE,15,BX_GPIO_MODE_INPUT);
	bx_set(id_gpio,BXP_GPIO_PULL,15,BX_GPIO_PULLUP);
	
    bx_call(id0,BXM_OPEN,0,0);
	bx_call(id1,BXM_OPEN,0,0);
	bx_call(id2,BXM_OPEN,0,0);
	bx_call(id3,BXM_OPEN,0,0);
	bx_call(id4,BXM_OPEN,0,0);
		
	bx_set(id0,BXP_PIN,PWM0_PIN,0);
	bx_set(id1,BXP_PIN,PWM1_PIN,0);
	bx_set(id2,BXP_PIN,PWM2_PIN,0);	
	bx_set(id3,BXP_PIN,PWM3_PIN,0);	
	bx_set(id4,BXP_PIN,PWM4_PIN,0);

	bx_call(id0,BXM_START,1000,0);
	bx_call(id1,BXM_START,50000,20);
	bx_call(id2,BXM_START,160000,50);
	bx_call(id3,BXM_START,10000,40);
	bx_call(id4,BXM_START,1000,100);
	

	while(1)
	{
	    bx_call(id_gpio,BXM_READ,(u32)&pin_value,0);
			
		if(!(pin_value>>15))
		{
		    if(duty_value >= 100)
				duty_value = 0;
			else
				duty_value += 10;

			
			
			bx_call(id0,BXM_START,1000,duty_value);

			BX_DELAY_US(1000*1000);
		}
	}

}
/** ---------------------------------------------------------------------------
 * @brief   :
 * @note    :
 * @param   :
 * @retval  :
-----------------------------------------------------------------------------*/
bx_err_t user_msg_handle_func(s32 svc, u32 msg,u32 param0,u32 param1 )
{

    return BX_OK;
}
/*========================= end of exported function =========================*/


/*============================= import function ==============================*/

/*=========================== end of import function =========================*/


/*============================ interrupt function ============================*/

/*========================= end of interrupt function ========================*/

  
/******************** (C) COPYRIGHT BLUEX **********************END OF FILE****/



